1  Getting started

1.1 Build a Reference Database

The build_ref_db() function constructs a reference database from functional annotations and taxonomic classifications.

library(f3mr)
library(here)

# Paths to annotation files
funct_annotations_path <- here::here("data-raw/meat_ref_db/f3m_meat_genes_catalog_20241211_funct_annotations.tsv")
gtdb_classification_path <- here::here("data-raw/meat_ref_db/meat_genes_catalog_gtdb_classification.tsv")

# Build the reference database
meat_ref_db <- build_ref_db(
  funct_annotations_path = funct_annotations_path,
  gtdb_classification_path = gtdb_classification_path
)

# Preview the functional annotations
head(meat_ref_db$funct_annotations)

1.2 Import Sample Counts

The import_sample_count() function reads and formats sample count data from a file.

# Path to sample count file
sample_count_path <- here::here("data-raw/smfood/mRNA-SMF01-MAP-AB-T06_genes_abundancies_with_species_and_functions.tsv")

# Import sample count
sample_count <- import_sample_count(sample_count_path = sample_count_path)

# Preview sample count
head(sample_count)

1.3 Aggregate Counts

The aggregate_counts() function aggregates counts at specified taxonomic and functional levels.

# Define aggregation levels
taxonomic_level <- "genus"
functional_level <- "food_microbiome_metabolic_function"

# Aggregate counts
aggregated_counts <- aggregate_counts(
  all_sample_counts = all_sample_counts,
  ref_db = meat_ref_db,
  taxonomic_level = taxonomic_level,
  functional_level = functional_level
)

# Preview aggregated counts
head(aggregated_counts)

1.4 Build a Count Matrix

The build_count_matrix() function creates a count matrix suitable for downstream analyses such as DESeq2.

# Build count matrix
count_matrix <- build_count_matrix(
  aggregated_counts = aggregated_counts,
  deseq2 = TRUE
)

# Preview count matrix
head(count_matrix)

1.5 Usage Workflow

Below is a step-by-step guide to using the package:

  1. Build the reference database:

    meat_ref_db <- build_ref_db(funct_annotations_path, gtdb_classification_path)
  2. Import multiple sample count files:

    all_sample_counts <- import_multiple_samples(folder_path)
  3. Aggregate counts:

    aggregated_counts <- aggregate_counts(
      all_sample_counts = all_sample_counts,
      ref_db = meat_ref_db,
      taxonomic_level = "genus",
      functional_level = "food_microbiome_metabolic_function"
    )
  4. Build a count matrix:

    count_matrix <- build_count_matrix(aggregated_counts, deseq2 = TRUE)
  5. Explore the count matrix:

    head(count_matrix)